Repository navigation
Dev: Write up database core tables and schema - #6
Merged
Merged
Conversation
Entities and generated migration for users, imports, daily/hourly/scheduled observations, daily records and audit log, plus docs/database-schema.md mapping each column to its source cell in the example sheets.
Add s3Key to imports in the doc.
Client confirmed more stations are coming, so stationId joins the keys of the three daily tables now rather than in a later migration. Every row comes from an upload, so importId is not null on observations and records.
Keying records by station now avoids changing their primary key later if records become per-station. The hourly notes now say what column H's fractions and column I's weather codes mean.
naman0r
marked this pull request as ready for review
October 6, 2026 01:14
Rayna-Yu
approved these changes
Oct 6, 2026
Rayna-Yu
left a comment
Collaborator
There was a problem hiding this comment.
Looks good to me!
Non-blocking: One thing to note though, is I think pg parses a Postgres date at the server's local midnight. So that would be UTC in Lambda and Eastern for our laptops. This shouldn't be an issue because we are planning on running everything in Lambdas anyways, but something that we may need to be careful about.
CharlesTChapman
approved these changes
Oct 8, 2026
CharlesTChapman
left a comment
There was a problem hiding this comment.
Looks good to me. All entities and fields match sample data well and relational structure seems logical.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ℹ️ Issue
Closes #3
📝 Description
Adds the BHO database schema. The doc describes each table, and the migration creates the tables in Postgres.
docs/database-schema.mdlists every table and column, with the spreadsheet cell each column comes from.db/migrations/0001_init_schema.tsis a Kysely migration. It createsusers,stations,imports,daily_observations,hourly_observations,scheduled_observations,daily_records, andaudit_log, and adds station19737-02. Deleting a day also deletes its hourly and scheduled rows.downdrops everything.audit_logrow per insert, update, or delete. To record who made a change, the writer callsset_config('app.user_id', ..., true)andset_config('app.import_id', ..., true)in its transaction.db/types.tshas the Kysely type for each table.db/client.tshascreateDb(), which returnsdatecolumns as'YYYY-MM-DD'strings. By defaultpgreturns aDateat local midnight, so2026-07-01is04:00Zon a laptop in Eastern time and00:00Zin Lambda.kysely@^0.27.0to the rootpackage.json, the same version the Lambdas use.Only
audit_log.actionis an enum. Values that may change, likeimports.status, are text.✔️ Verification
Ran the migration against Postgres 16 in Docker with Kysely's
MigratorandFileMigrationProviderpointed atdb/migrations. Until #11 addsyarn db:migrate, that is the way to run it. Checked that:up,down, andupagain succeed, anddownleaves no tables, type, or function behind.audit_logrow with the row's key and the user.TZ=America/New_York,createDb()reads2026-07-01back as the string"2026-07-01".🏕️ (Optional) Future Work / Notes
hourly_observations.mountainVis(1@1.5) stays text. The client says it is mountain number @ visibility on a 1-3 scale. Once the weather group says which number is which mountain, split it intomountainIdandmountainVisibilitywith amountainstable.28 WNW @ 1631E, 1651E), and July 19 has two directions.peakGustDirandpeakGustTimehold one value each.daily_observations.remarksreads G47-G49, but notes also appear in G50-G54 on some days.importIdis required ondaily_observationsanddaily_records, which assumes only uploads write weather data. If staff can edit values in the app, it needs to be nullable.importIdchanged.